﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;

namespace 音乐播放盒
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (TestAlreadyRun())
            {
                MessageBox.Show("电脑上已经有一个相同程序在运行!\n请先关闭程序!");
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new 主窗口());
        }

        public static bool TestAlreadyRun()
        {
            Process currentProcess = Process.GetCurrentProcess();
            Process[] processes = Process.GetProcesses();
            int i = 1;

            foreach (Process process in processes)
            {
                if (currentProcess.ProcessName == process.ProcessName)
                {
                    if (i == 2)
                        return true;
                    i++;
                }
            }

            return false;
        }
    }
}
